<template>
  <div class="home-container">
    <div class="header-block">
      <el-menu :default-active="activeIndex"
               class="el-menu-demo"
               mode="horizontal"
               @select="handleSelect"
               background-color="#83AF9B"
               text-color="#FFFFFF"
               active-text-color="#C8C8A9"
               router
      >
        <el-menu-item index="#">
          <img src="../static/house.png" style="height: 60px; width: 70px; ">
        </el-menu-item>
        <el-menu-item index="/home/index" v-if="user.type === 1">首页</el-menu-item>
<!--        <el-menu-item index="/home/hire" v-if="user.type === 1">租房</el-menu-item>-->
        <el-menu-item index="/home/hostHome" v-if="user.type === 2">首页</el-menu-item>
        <el-menu-item index="/home/lease" v-if="user.type === 2">
          我要出租
        </el-menu-item>
        <el-menu-item index="/home/orderManage" v-if="user.type === 2">
          租赁信息
        </el-menu-item>
        <el-menu-item index="/home/uploadHousePic" v-if="user.type === 2">
          上传房屋图片
        </el-menu-item>
      </el-menu>
      <div class="avatar-block">
          <div style="display: inline-block; padding-right: 10px; position:relative; top: 10%; transform: translateY(10%);">
            <el-avatar :src="user.avatar" size="medium"></el-avatar>
          </div>
          <div style="display: inline-block; font-size: 20px; font-weight: 700; line-height: 60px;">
            <a-dropdown>
              <a class="ant-dropdown-link" @click="e => e.preventDefault()" >
                {{user.nickname}}<a-icon type="down" />
              </a>
              <a-menu slot="overlay" style="margin-top: 15px;">
                <a-menu-item>
                  <a href="/home/profile">个人中心</a>
                </a-menu-item>
                <a-menu-item>
                  <a href="/home/modifyPassword">修改密码</a>
                </a-menu-item>
                <a-menu-item>
                  <span @click="handleClose">退出</span>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
      </div>
    </div>
    <div class="line"></div>
    <el-container class="tab-bar">
      <el-main style="overflow: hidden;">
        <router-view/>
      </el-main>
      <el-footer></el-footer>
    </el-container>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        user: {
          nickname: '',
          avatar: '',
          type: ''
        },
        activeIndex: '/home/index'
      }
    },
    created() {
      const _this = this
      let username = localStorage.getItem('username')
      _this.$http.get('/user/getUserByUsername/'+ username).then(function (resp) {
        if(resp.data.data.avatar != null)
        {
          _this.user.avatar = require('../static/user/'+ resp.data.data.avatar)
        }
        _this.user.nickname = resp.data.data.nickname
        _this.user.type = resp.data.data.type
      })
    },
    methods: {
      handleClose() {
        localStorage.removeItem('userId')
        localStorage.removeItem('username')
        this.$router.push({name: 'Login'})
      },
      handleSelect: function (e) {
        console.log(e)
      }
    }
  }
</script>

<style scoped>
  .home-container {
    padding: 0;
  }
  .home-container .el-menu-demo el-menu-item{
    height: 40px;
  }
  .header-block {
    display: flex;
    background-color: #83AF9B;
    width: 100%;
    height: 60px;
    justify-content: space-between;
  }
  .el-menu-demo {
    margin-left: 100px;
  }
  .avatar-block {
    align-self: center;
    margin-right: 150px;
    width: 200px;
    height: 60px;
  }
  .el-dropdown-link {
    cursor: pointer;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .dropdown-container {
    margin-top: 60px;
  }
  .ant-dropdown-link {
    font-size: 18px;
    font-weight: 700;
    color: white;
  }
  .tab-bar {
    width: 1196px;
    height: 100%;
    margin: 0 auto;
  }
</style>
